package graphics;

import data.Map;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;

/**
 * graphics
 *
 * @author Jared Moore
 * @date 10/16/13
 */
public class OuterPanel extends JPanel
{

	public OuterPanel(final Map map)
	{
		setSize(800, 600);
		setLayout(new BorderLayout());

		JPanel panel = new JPanel();

		final JLabel label = new JLabel("Time Left:  50");
		final JLabel label1 = new JLabel(String.format("Current Player:  %s  ", map.getCurrentPlayer().toString()));
		panel.add(label1, BorderLayout.EAST);
		Timer timer = new Timer(1000, new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent actionEvent)
			{
				String text = label.getText();
				text = text.substring(12);
				Scanner scanner = new Scanner(text);
				int timeLeft = scanner.nextInt();
				if (--timeLeft == 0)
				{
					timeLeft = map.getTurnLength(map.getCurrentPlayer()) / 1000;
				}
				label.setText(String.format("Time Left:  %d", timeLeft));
				label1.setText(String.format("Current Player:  %s  Money: %d", map.getCurrentPlayer().toString(),map.getCurrentPlayer().getMoney()));
			}
		});
		timer.start();
		panel.add(label, BorderLayout.WEST);
		add(panel, BorderLayout.NORTH);
		add(new MULEPanel(map), BorderLayout.CENTER);
	}
}
